<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue组件</title>
    <script src="https://unpkg.com/vue@next"></script>
    <!-- 
        1.使用content="",props传递值
        2.使用v-bind,动态参数传递
        3.子组件对父组件传过来的数据进行校验
        
     -->
</head>
<body>
    <div id="root"></div>
    <script>
        // vue的生命周期函数
        const app = Vue.createApp({
            data() {
                return {
                    message: ()=>{
                        console.log("测试");
                    },
                    num: 10001
                }
            },
            template: `
                <div>
                    <test :content="num" />
                </div>
            `
        });
        app.component('test',{
            // 父组件对子组件的传值校验,可以校验String类型,Boolean类型,Array数组类型,Object类型,Function函数类型
            props: {
                content: {
                    typeof: Number,
                    validator: function (value) {
                        return value <1000
                    },
                    default: 222
                }
            },
            methods: {
                btn(){
                    this.content()
                }
            },
            template: `
                <div @click="btn">
                    {{ content}}
                </div>
            `
        })
        const vm = app.mount('#root');
    </script>
</body>
</html>